cmake_minimum_required(VERSION 3.5 FATAL_ERROR)

project(recipe-01 LANGUAGES NONE)

find_package(PythonInterp REQUIRED)                 # find_package 命令找到Python解释器，可以添加具体的版本号, REQUIRED表示强制需求，否则暂停

message(STATUS "PYTHONINTERP_FOUND is: ${PYTHONINTERP_FOUND}")              # 是否找到解释器
message(STATUS "PYTHON_EXECUTABLE is: ${PYTHON_EXECUTABLE}")                # Python解释器到可执行文件的路径，也可以外部使用cmake -D PYTHON_EXECUTABLE=...
message(STATUS "PYTHON_VERSION_STRING is: ${PYTHON_VERSION_STRING}")        # Python解释器的完整版本信息 2.7.17
message(STATUS "PYTHON_VERSION_MAJOR is: ${PYTHON_VERSION_MAJOR}")          # Python解释器的主要版本号 2
message(STATUS "PYTHON_VERSION_MINOR is: ${PYTHON_VERSION_MINOR}")          # Python解释器的次要版本号 7
message(STATUS "PYTHON_VERSION_PATCH is: ${PYTHON_VERSION_PATCH}")          # Python解释器的补丁版本号 17

execute_process(COMMAND ${PYTHON_EXECUTABLE} "-c" "print('Hello World!')"
        RESULT_VARIABLE _status
        OUTPUT_VARIABLE _hello_world
        ERROR_QUIET                                                         # OUTPUT_QUIET忽略标准输出、错误输出ERROR_QUIET
        OUTPUT_STRIP_TRAILING_WHITESPACE)                                   # 有个空行

# 两种方式
include(CMakePrintHelpers)                                                  # cmake的调试模块
cmake_print_variables(_status _hello_world)

message(STATUS "RESULT_VARIABLE is: ${_status}")
message(STATUS "OUTPUT_VARIABLE is: ${_hello_world}")